home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / obinded.com / SMED.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1991-03-05  |  2.6 KB  |  110 lines

  1. {$X+}
  2. uses crt, obined;
  3. var
  4.    ed : edcb;
  5.  
  6. const
  7.    ExitCommands : array [1..9] of Char = #1#27#2#0#45#2#0#18#0;
  8.  
  9. procedure EventHandler(EventNo, KbdFlagInfo : Word); far;
  10. const
  11.    count : integer = 0;
  12.    prev_lpos : integer = 0;
  13. var
  14.    s     : string;
  15.    ch    : char;
  16.    lpos  : integer;
  17.    llen  : integer;
  18.    inins : boolean;
  19. begin
  20.    if count > 0 then begin
  21.       dec(count);
  22.       exit;
  23.    end;
  24.    with CurrInternals^ do begin
  25.       lpos := linepos;
  26.       llen := linelen;
  27.       str(llen:2, s);crtputfast(72, 25, calow+'Length '+s);
  28.       str(ord(currchar):3, s);crtputfast(1, 25, calow+'Ascii '+s);
  29.       if (llen > 70)
  30.       and (lpos = llen+2)
  31.       and (lpos = succ(prev_lpos)) then begin
  32.          inins := (editoptions and edoptinsert) = edoptinsert;
  33.          clearkbd;
  34.          if not inins then
  35.             stuffkey($5200);
  36.          if llen > 78 then
  37.             stuffkey($7300);
  38.          stuffkey(ord(^M));
  39.          if llen > 78 then begin
  40.             stuffkey($7400);
  41.             stuffkey(ord(' '));
  42.          end;
  43.          if not inins then
  44.             stuffkey($5200);
  45.          count := 7;
  46.       end;
  47.       prev_lpos := lpos;
  48.    end;
  49. end;
  50.  
  51. function confirm_abort : integer;
  52. var
  53.    s  : string;
  54.    ch : char;
  55. begin
  56.    s := caerr+'┌─────────────────────┐';crtputfast(29, 11, s);
  57.    s := caerr+'│Enter - Confirm Abort│';crtputfast(29, 12, s);
  58.    s := caerr+'│Esc   - Resume Edit  │';crtputfast(29, 13, s);
  59.    s := caerr+'└─────────────────────┘';crtputfast(29, 14, s);
  60.    repeat
  61.      ch := readkey;
  62.      if ch = #0 then readkey;
  63.    until ch in [#13,#27];
  64.    if ch = #13 then confirm_abort := -1 else confirm_abort := 0;
  65. end;
  66.  
  67. procedure edit(fname : string);
  68. var
  69.    result : integer;
  70.    s : string;
  71.    i,n : integer;
  72.    allocsize : word;
  73. begin
  74.    if maxavail > maxfilesize then
  75.       allocsize := maxfilesize
  76.    else
  77.       allocsize := maxavail;
  78.    ed.init(allocsize, 1, 1, 80, 24,
  79.            true, edoptinsert, '.', exitcommands, @EventHandler);
  80.    if ed.read(fname) > 1 then halt;
  81.    ed.reset;
  82.    s := 'Prodigy Computing (Pty) Limited - Small Editor';
  83.    n := 80 - length(s);
  84.    for i := 1 to n div 2 do
  85.       insert(' ', s, 1);
  86.    for n := length(s)+1 to 80 do
  87.       s := s + ' ';
  88.    crtputfast(1,25,calow+s);
  89.    repeat
  90.       result := ed.use('');
  91.       case result of
  92.         -1: begin
  93.            ed.save(false);
  94.         end;
  95.         else begin
  96.            if not ed.modified then
  97.               result := -1
  98.            else
  99.               result := confirm_abort;
  100.         end;
  101.       end;
  102.    until result = -1;
  103. end;
  104.  
  105. begin
  106.    if paramcount > 0 then
  107.       edit(paramstr(1));
  108.    clrscr;
  109. end.
  110.